using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VAKSHCHG
    {
        public DataRow Convert2AKSHCHG(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryAKSHCHG(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["AKCMANDANT"] = " ".PadRight(2 ); 
         dwReturn["AKCDATE"] = " ".PadRight(8 ); 
         dwReturn["AKCTIME"] = " ".PadRight(8 ); 
         dwReturn["AKCLFD"] = " ".PadRight(2 ); 
         dwReturn["AKCPERSNR"] = " ".PadRight(8 ); 
         dwReturn["AKCNRKRS"] = " ".PadRight(2 ); 
         dwReturn["AKCLFDNR"] = " ".PadRight(4 ); 
         dwReturn["AKCPOS"] = " ".PadRight(2 ); 
         dwReturn["AKCAENZL"] = " ".PadRight(0 ); 
         dwReturn["AKCNEUB"] = " ".PadRight(8 ); 
         dwReturn["AKCNEUD"] = " ".PadRight(0 ); 
         dwReturn["AKCSTATUS"] = " ".PadRight(1 ); 
         dwReturn["AKCCHGTYP"] = " ".PadRight(2 ); 
         dwReturn["AKCDURATION"] = " ".PadRight(0 ); 
         dwReturn["AKCORIGIN"] = " ".PadRight(1 ); 
         dwReturn["AKCSHNR"] = " ".PadRight(1 ); 
         dwReturn["AKCSET"] = " ".PadRight(2 ); 
         dwReturn["AKCJOB"] = " ".PadRight(5 ); 
         dwReturn["AKCBENID"] = " ".PadRight(8 ); 
         dwReturn["AKCFILLER2"] = " ".PadRight(28 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapAKSHCHG(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveAKSHCHG(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryAKSHCHG(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapAKSHCHG(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertAKSHCHG(dwLocal, ITXDBVERSION);
            }
            UpdateAKSHCHG(dwLocal);
        }
        public void InsertAKSHCHG(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO AKSHCHG(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryAKSHCHG(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM AKSHCHG WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM AKSHCHG  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "AKSHCHG";
            Return = Result;
            return Return;
        }
        public void DeleteAKSHCHG(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM AKSHCHG   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateAKSHCHG(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE AKSHCHG SET "
                    +"AKCMANDANT= :AKCMANDANT,"
                    +"AKCDATE= :AKCDATE,"
                    +"AKCTIME= :AKCTIME,"
                    +"AKCLFD= :AKCLFD,"
                    +"AKCPERSNR= :AKCPERSNR,"
                    +"AKCNRKRS= :AKCNRKRS,"
                    +"AKCLFDNR= :AKCLFDNR,"
                    +"AKCPOS= :AKCPOS,"
                    +"AKCAENZL= :AKCAENZL,"
                    +"AKCNEUB= :AKCNEUB,"
                    +"AKCNEUD= :AKCNEUD,"
                    +"AKCSTATUS= :AKCSTATUS,"
                    +"AKCCHGTYP= :AKCCHGTYP,"
                    +"AKCDURATION= :AKCDURATION,"
                    +"AKCORIGIN= :AKCORIGIN,"
                    +"AKCSHNR= :AKCSHNR,"
                    +"AKCSET= :AKCSET,"
                    +"AKCJOB= :AKCJOB,"
                    +"AKCBENID= :AKCBENID,"
                    +"AKCFILLER2= :AKCFILLER2,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("AKCMANDANT", OracleType.NVarChar).Value = dwData["AKCMANDANT"].ToString(); 
          or1.Parameters.Add("AKCDATE", OracleType.NVarChar).Value = dwData["AKCDATE"].ToString(); 
          or1.Parameters.Add("AKCTIME", OracleType.NVarChar).Value = dwData["AKCTIME"].ToString(); 
          or1.Parameters.Add("AKCLFD", OracleType.NVarChar).Value = dwData["AKCLFD"].ToString(); 
          or1.Parameters.Add("AKCPERSNR", OracleType.NVarChar).Value = dwData["AKCPERSNR"].ToString(); 
          or1.Parameters.Add("AKCNRKRS", OracleType.NVarChar).Value = dwData["AKCNRKRS"].ToString(); 
          or1.Parameters.Add("AKCLFDNR", OracleType.NVarChar).Value = dwData["AKCLFDNR"].ToString(); 
          or1.Parameters.Add("AKCPOS", OracleType.NVarChar).Value = dwData["AKCPOS"].ToString(); 
          or1.Parameters.Add("AKCAENZL", OracleType.NVarChar).Value = dwData["AKCAENZL"].ToString(); 
          or1.Parameters.Add("AKCNEUB", OracleType.NVarChar).Value = dwData["AKCNEUB"].ToString(); 
          or1.Parameters.Add("AKCNEUD", OracleType.NVarChar).Value = dwData["AKCNEUD"].ToString(); 
          or1.Parameters.Add("AKCSTATUS", OracleType.NVarChar).Value = dwData["AKCSTATUS"].ToString(); 
          or1.Parameters.Add("AKCCHGTYP", OracleType.NVarChar).Value = dwData["AKCCHGTYP"].ToString(); 
          or1.Parameters.Add("AKCDURATION", OracleType.NVarChar).Value = dwData["AKCDURATION"].ToString(); 
          or1.Parameters.Add("AKCORIGIN", OracleType.NVarChar).Value = dwData["AKCORIGIN"].ToString(); 
          or1.Parameters.Add("AKCSHNR", OracleType.NVarChar).Value = dwData["AKCSHNR"].ToString(); 
          or1.Parameters.Add("AKCSET", OracleType.NVarChar).Value = dwData["AKCSET"].ToString(); 
          or1.Parameters.Add("AKCJOB", OracleType.NVarChar).Value = dwData["AKCJOB"].ToString(); 
          or1.Parameters.Add("AKCBENID", OracleType.NVarChar).Value = dwData["AKCBENID"].ToString(); 
          or1.Parameters.Add("AKCFILLER2", OracleType.NVarChar).Value = dwData["AKCFILLER2"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
